<?php
/**
 * Created by 荣耀电竞.
 * User: 林子彦 <278805354@qq.com>
 * Date: 2018/6/13 0013
 * Time: 10:12
 */

namespace App\Content\Repositories;
use App\Content\Contracts\AdvInterface;

use App\Content\Models\AdvModel;
use Illuminate\Support\Facades\Request;


/**
 * 广告
 * Class DbGoodsRepository
 * @package App\Shop\Repositories
 */
class DbAdvRepository implements AdvInterface
{
    /**
     * 广告模型
     * @return AdvModel
     */
    public function getAdvModel(){
        return app()->make(AdvModel::class);
    }

    /**
     * 公告列表
     * @param $where
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|mixed
     */
    public function getList($where){
        $request=Request::instance();
        $limit=empty($request->input("limit"))?10:$request->input("limit");
        $sort=empty($request->input("sort"))?'list_order':$request->input("sort");
        $order=empty($request->input("order"))?'asc':$request->input("order");
        $select=empty($request->input("select")) ? '*' : explode(",",$request->input("select"));
        return $this->getAdvModel()->newQuery()->select($select)->where($where)->orderBy($sort,$order)->paginate($limit);
    }

    /**
     * 保存公告数据
     * @param $data
     * @return mixed|void
     */
    public function saveData($data){
        if(empty($data['status'])){
            $data['status']=0;
        }
        $data["uid"]=UID;
        return $this->getAdvModel()->newQuery()->updateOrCreate(["id"=>$data['id']],$data);
    }

    /**
     * 获取公告单条信息
     * @param $id
     * @return mixed|void
     */
    public function getInfo($id){
        return $this->getAdvModel()->newQuery()->where("id",$id)->first();
    }

    /**
     * 删除数据
     * @param $where
     * @return mixed
     */
    public function deleteData($where){
        return $this->getAdvModel()->newQuery()->where($where)->delete();
    }


}